package com.bawei.module_live.ui.view

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.lxj.xpopup.core.BottomPopupView
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.widget.ViewPager2
import com.bawei.module_live.R
import com.bawei.module_live.ui.adapter.FragmentAdapter
import com.bawei.module_live.ui.fragment.OrderHotAllFragment
import com.bawei.module_live.ui.fragment.OrderHotDaihuoFragment

class RankingPopup(
    context: Context,
    private val activity: FragmentActivity, // 传Activity用于FragmentManager
    private val defaultTab: Int = 0 // 默认选中Tab
) : BottomPopupView(context) {

    override fun getImplLayoutId(): Int = R.layout.ranking_layout



    override fun onCreate() {
        super.onCreate()
        val tabList = listOf("全站榜", "带货榜")
        val vp2 = findViewById<ViewPager2>(R.id.viewPager)
        val tl = findViewById<TabLayout>(R.id.tabLayout)

        // Fragment列表
        val fragments = listOf(
            OrderHotAllFragment(),
            OrderHotDaihuoFragment()
        )
        vp2.adapter = FragmentAdapter(activity, fragments)

        // TabLayout与ViewPager2联动
        TabLayoutMediator(tl, vp2) { tab, position ->
            tab.text = tabList[position]
        }.attach()

        // 默认选中
        vp2.setCurrentItem(defaultTab, false)
    }
}